package com.balabala.handler;
import com.balabala.exception.CustomerException;
import com.balabala.gym_enum.ExceptionEnum;
import com.balabala.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 *
 * @author 何涛
 * @date 2023/4/24 0024
 */

@ControllerAdvice
@Slf4j
public class ControllerExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result notKnowException(Exception e)
    {
        log.error("系统异常：{}",e.getMessage());
        return Result.fail(444,e.getMessage());
    }
    @ExceptionHandler(CustomerException.class)
    @ResponseBody
    public Result customerException(CustomerException e)
    {
        log.info("自定义异常：{}",e.getMessage());
        return Result.fail(e.getCode(),e.getMsg());
    }
    @ExceptionHandler(IllegalArgumentException.class)
    @ResponseBody
    public Result illegalArgumentException(IllegalArgumentException illegalArgumentException)
    {
        log.info("断言异常：{}",illegalArgumentException.getMessage());
        return Result.fail(444,illegalArgumentException.getMessage());
    }
}
